var final = location.pathname.split('/').slice(-2)[0];
var host = window.location.host;
var Min = 1, Max = 9;
var getRand = (function(){
    var Range = Max - Min;
    var Rand = Math.random();
    return Min + Math.round(Rand * Range);
})(Min,Max);
var bottom_chat_status = 1;

/*时间格式转换*/
Date.prototype.Format = function (fmt) {
    var o = {
        "M+": this.getMonth() + 1, //月份
        "d+": this.getDate(), //日
        "h+": this.getHours(), //小时
        "m+": this.getMinutes(), //分
        "s+": this.getSeconds(), //秒
        "q+": Math.floor((this.getMonth() + 3) / 3),
        "S": this.getMilliseconds() //毫秒
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
};

/*PtEngine*/
var id = final ? '63f924fd' : '45868240';
window._pt_lt = new Date().getTime();
window._pt_sp_2 = [];
_pt_sp_2.push('setAccount,' + id);
var _protocol = (("https:" == document.location.protocol) ? " https://" : " http://");
(function() {
    var atag = document.createElement('script'); atag.type = 'text/javascript'; atag.async = true;
    atag.src = _protocol + 'js.ptengine.cn/' + id + '.js';
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(atag, s);
})();

function lazyLoadImg(){
    $('img[src*="ico-1"]').each(function(){
        $(this).attr('src', $(this).attr('alt'));
    });
}












(function(){
    var mymenu = '<div class="fixed-menu"><div class="return"><span>项目导航</span><i>返回</i></div><div class="fixed-menu-nav"><div id="item_nav"><div class="swiper-container item_nav"><ul class="swiper-wrapper"><li class="swiper-slide"><a href="/brand/">禾美品牌</a></li><li class="swiper-slide"><a href="/doctor/">禾美医生</a></li><li class="swiper-slide"><a href="/case/">禾美案例</a></li><li class="swiper-slide"><a href="/subject/shproject/mljs/">禾美技术</a></li><li class="swiper-slide"><a href="/subject/shproject/aqtx/">安全体系</a></li><li class="swiper-slide"><a href="/ambient/">禾美环境</a></li></ul></div></div></div><div class="project_content_box"><div class="project_main"><ul class="project_nav"></ul><div class="project_item"></div></div></div></div>';
    $('body').append(mymenu);
    $.ajax({
        url : "/plus/banners.php?t=projects",
        type : "get",
        dataType : "json",
        async : false,
        success : function(projects){
            var i = 0;
            for(var n in projects){
                $('.project_nav').append('<li>' + n + '</li>');
                $('.project_item').append('<div class="item_box"></div>');
                for(var m in projects[n]){
                    $('.item_box:eq(' + i + ')').append('<dl><dt>' + m + '</dt></dl>');
                    for(var o = 0; o < projects[n][m].length; o++){
                        $('.item_box:eq(' + i + ') dl dt:contains("' + m + '")').parent().append('<dd><a href="' + projects[n][m][o][0] + '">' + projects[n][m][o][1] + '</a></dd>');
                    }
                }
                i++;
            }
            $(".project_nav li:eq(0)").addClass('on');
        }
    });

    var swiper = document.createElement("script");
    swiper.src = "/js/swiper.min.js";
    var js = document.getElementsByTagName("script")[0];
    js.parentNode.insertBefore(swiper, js);
})();

function eyes(){
    var eye = ['qdmmou', 'qdmm1', 'shuangypjg', 'sypjg1', 'kdyy', 'whqyd', 'maixsyp', 'kyjjg', 'yb', 'sjxc', 'mxsypkb', 'sypal', 'sypkb', 'sypk', 'ybxfu', 'mxsyp', 'xssyp', 'blsyp', 'hssyp'];
    return eye.indexOf(final) != -1 || false;
}




function swi(c){
    var mySwiper = new Swiper(c, {
        spaceBetween: 0,
        slidesPerView: 4,
        touchRatio: 0.3,
        freeMode : true,
        loop: false,
        loopedSlides: 4,
        slideToClickedSlide: false
    });
}

function showLeftMenu(){
    swi('.item_nav');
    $('.fixed-menu').css({animation:'showit 0.6s 0.1s ease both'});
    $('.fixed-menu').animate({left:0});
    if($('#item_nav .item_nav ul li a').css('font-size').replace('px', '') > 20){
        $('#item_nav .item_nav ul li a').css('font-size', function(){
            return $(this).css('font-size').replace('px','')/1.5+'px';
        });
        $('.project_nav li').css('font-size', function(){
            return $(this).css('font-size').replace('px','')/1.5+'px';
        });
        $('.item_box dl dt').css('font-size', function(){
            return $(this).css('font-size').replace('px','')/1.5+'px';
        });
        $('.item_box dl dd').css('font-size', function(){
            return $(this).css('font-size').replace('px','')/1.4+'px';
        });
    }
}

$(function() {
    //取本地cookie
    var cookies = {};
    var cookie  = document.cookie.split(';');
    for(var i = 0; i < cookie.length; i++){
        cookies[cookie[i].split('=')[0].replace(/ /g, '')] = cookie[i].split('=')[1];
    }

    //通用导航栏
    var ww = $('body').width(), wh = $(window).height(), ih = wh-$('#item_nav').height()-$(".newHead").height();
    $(".fixed-menu").css({width:ww, left:-ww});
    $(".return").height($(".newHead").height());
    $(".project_content_box").css({width:ww, height:wh});
    $(".project_nav").css({height:ih});
    $(".project_item").css({height:ih});
    $(".project_main .project_item .item_box").first().show().siblings().hide();
    $(".project_nav li").click(function () {
        var i = $(this).index();
        $(this).addClass('on').siblings().removeClass('on');
        $(".project_main .project_item .item_box").eq(i).show().siblings().hide();
    });


    function mp() {
        $('#fixtop').remove();
        $(".top_tips").animate({
            top: "-50px"
        }, 1e3, function() {
            setTimeout(mb, 15e3);
        });
    }

    function mb() {
        var hei = $(".top_tips").height();
        $('#fixtop').animate({
            height: hei
        }, 1001);
        $(".top_tips").animate({
            top: '0'
        }, 1000, function() {
            setTimeout(mp, 10e3);
        });
    }
    setTimeout(mb, 8000);

    function swt_tb() {
        $(".youhui-b").animate({bottom: '0'},1500);
        $(".youhui_close").click(function(){
            bottom_chat_status++;
            $(".youhui-b").animate({bottom: '-30%'},1000);
            setTimeout(function(){
                $(".youhui-b").animate({bottom: '0'},1500);
            }, 20000);
        });
    }
    setTimeout(swt_tb, 1500);

    /*顶部项目导航*/

    $('#item_nav .item_nav ul li').click(function(){
        i = $(this).index();
        $(this).addClass('on').siblings().removeClass('on');
    });

    $('.navBtn').click(function(){
        showLeftMenu(this);
    });
    $(".return i").click(function(){
        $('.fixed-menu').css({animation:'hideit 0.6s 0.1s ease both'});
        $('.fixed-menu').animate({left:'-1000px'});
    });


    $('.subject_activity:eq(0)').after('<div id="call_form"><div class="call_form_l"><input type="text" name="call_tel" id="call_tel" placeholder="请输入您的电话号码" class="callbF_text"><input type="submit" name="submit" value="免费回电" class="callbF_sub" id="livecall" ></div><a class="call_form_r" href="javascript:void(0);" onclick="openK(this);return false;">咨询价格优惠</a></div>');

});

$(document).scroll(function(){
    lazyLoadImg();
});
function addBS(a, b, p){
    $(a).each(function(i){
        var name = $(this).attr('src').match(/\/([a-z]+)\.(jpg|png)/)[1];
        $(this).parents(a.split(' ')[0]).find('a:eq(' + i + ')').attr('title', b + name + '_' + p);
    });
}
function addTY(){
    $('a[onclick*="openK"]').each(function(i){
        var exclude = ['call_form_r'];
        if($(this).attr('title') == undefined || $(this).attr('title').indexOf('wap') == -1)
            if(exclude.indexOf(this.className) == -1){
                $(this).attr('title', 'wap_' + i + '_' + path);
            } else {
                $(this).attr('title', 'wap_' + this.className + '_' + path);
            }
    });
}

function eachA(){
    var path = final || 'index';
    var chatWhere = {
        '.top_tips' : 'wap_top_wx',
        '.zixun' : 'wap_top_zx',
        '.botchat' : 'wap_bottom_zx',
        '#qchat' : 'wap_bottom_send',
        '.youhui_close' : 'wap_bottom_close',
        '#banner_slider' : 'wap_subject_banner',
        '#yhChat' : 'wap_inner_send',
        '#moreInfo' : 'wap_project_more',
        '.navBtn' : 'wap_project_menu',
        '.lingjuan-logo a' : 'wap_hongbao',
        '.ty_doctor dt img' : 'wap_doc_',
        '.section_zj dt img' : 'wap_doc_'
    };

    for(var i in chatWhere){
        if($(i).length >= 1){
            if($(i).length > 1){
                addBS(i, chatWhere[i], path);
            } else {
                $(i).attr('title', chatWhere[i]);
            }
        }
    }
}




// 眼睛专题悬浮导航
    var eye = ["qdmmou","qdmm1","sypjg1","maixsyp","sypkb","kyjjg","sypal","mxsypkb","mxsyp","shuangypjg","qjkyj","blsyp","xssyp","sypk","sypal","sypkb","kdyy","sypjg","hssyp"];
    var path = location.pathname.split('/')[2];
    if($.inArray(path, eye) != -1){
        $('.main').after("<div class='t_hot'><div class='list a'><p>热门<br/>推荐</p></div><div class='list b'><p><a href='/subject/qdmm1/'>全度美眸<br/>大眼术</a></p></div><div class='list c'><p><a href='/subject/blsyp/'>白领范<br/>双眼皮</a></p></div><div class='list d'><p><a href='/subject/xssyp/'>学生范<br/>双眼皮</a></p></div><div class='list e'><p><a href='/subject/hssyp/'>韩式星范<br/>双眼皮</a></p></div></div>");
        $('.t_hot .list a[href="'+path+'"]').parent().parent().css("background","#403470");
        $(window).scroll(function(){
            var top = $(window).scrollTop();
            if(top>0){
                $('.t_hot').stop().animate({top:"0"}, 1000).css({position:"fixed"});
                $(".weixin").css({position:"absolute"});
            }else{
                $(".wrap").css({position:"relative"});
                $(".weixin").css({position:"fixed"});
                $('.t_hot').stop().animate({top:$('.main').height()}, 1000).css({position:"absolute"});
            }
        });
    }





